<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>修改用户信息</title>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.min.js"></script>
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.min.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/css/app.css?v=042403" rel="stylesheet" />
	<link rel="stylesheet" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/css/SUI.css?">
	<link rel="stylesheet" href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/font/iconfont.css">
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.picker.css" rel="stylesheet" />
	<link href="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/css/mui.poppicker.css" rel="stylesheet" />

	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.picker.js"></script>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/mui.poppicker.js"></script>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/city.data.js" type="text/javascript" charset="utf-8"></script>
	<script src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/mui/js/city.data-3.js" type="text/javascript" charset="utf-8"></script>
</head>
<style type="text/css">
		.suiLineInput dl input{margin: 0!important;padding:0;}
		.suiLineInput dl{height: 41px !important}
		.suiLineInput:nth-of-type(1) dl:first-child{height: 61px !important}
		.suiTag{margin-bottom: 0}
		button.mui-btn{border: #e54242}
</style>
<body class="edituserinfo">
	<form id="form">	
	<p class="suiTag">用户信息</p>
	<div class="suiLineInput strong">
		<dl>
			<dt>头像</dt>
			<dd style="background-image: url({{if .info.pathname}}{{.info.pathname}}{{else}}/static/wechat/img/add.png{{end}});">
				<input type="file" onchange='sword_uppic(this,"promotion",1)' accept="image/*">
				<input type="hidden" name="avatar" value="{{.info.avatar}}">
			</dd>
		</dl>
		<dl>
			<dt>用户名</dt>
			<dd><input type="text" placeholder="请输入用户昵称" name="monicker" value="{{.info.monicker}}"></dd>
		</dl>
		<dl>
			<dt>真实姓名</dt>
			<dd><input type="text" value="{{.info.name}}" name="name" placeholder="请输入真实姓名"></dd>
		</dl>
		<dl>
			<dt>性别</dt>
			<dd id="sex">{{if eq .info.sex "0"}}未知{{else if eq .info.sex "1"}}男{{else if eq .info.sex "2"}}女{{end}}</dd>
			<input type="hidden" value="{{.info.sex}}" name="sex">
		</dl>
	</div>
	<p class="suiTag">联系方式</p>
	<div class="suiLineInput strong">
		<dl>
			<dt>联系邮箱</dt>
			<dd><input type="text" placeholder="请输入邮箱" value="{{.mail}}" name="mail"></dd>
		</dl>
		<dl>
			<dt>微信号</dt>
			<dd><input type="text" placeholder="请输入微信号" value="{{.wechat}}" name="wechat"></dd>
		</dl>
	</div>
	</form>
	<button class="sure" id="up">确定</button>
</body>
</html>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/frame/sui/js/SUI.js"></script>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/zepto.min.js"></script>
<script type="text/javascript" src="https://tcsc.oss-cn-hangzhou.aliyuncs.com/static/wechat/js/sword_uppic.js"></script>
{{template "wechat/public/share.html" .}}
<script type="text/javascript">
 function serialize(form){
 var form=document.getElementById(form);
 var arr={};
	for (var i = 0; i < form.elements.length; i++) {
		    var feled=form.elements[i];
		    switch(feled.type) {
		    case undefined:
		    case 'button':
		    case 'file':
		    case 'reset':
		    case 'submit':
		    break;
		    case 'checkbox':
		    case 'radio':
		    if (!feled.checked) {
		    	break;
		    }
		    default:
		    if (arr[feled.name]) {
			    arr[feled.name]=arr[feled.name]+','+feled.value;
		    }else{
			    arr[feled.name]=feled.value;
		    } 
	    }
 	}
 	return arr
 }
document.getElementById("up").addEventListener("tap", function(){
	var info=serialize('form')
	if (!info.monicker){
	    mui.toast('请输入用户昵称!')
	    return false
	}
	var that=this
	that.disabled=true
	mui.ajax(window.location.href,{
		data:info,
		type:'post',
		timeout:10000,
		success:function(data){
			if(data==1){
	        mui.alert("","保存成功","确定",function(){
	            window.location.href=document.referrer
	        })
	       }else{
	        mui.alert("网络繁忙,请重试")
	       }
	       that.disabled=false
		},error:function(){
			 mui.alert("网络繁忙,请重试")
			that.disabled=false
		}
	})
});
	(function($, doc) {
		$.init();
		$.ready(function() {
			//普通示例
			var userPicker = new $.PopPicker();
			userPicker.setData([{
				text: '男',
				index:'1'
			}, {
				text: '女',
				index:'2'
			},{
				text: '未知',
				index:'0'
			}]);
			var sex = doc.getElementById('sex');
			sex.addEventListener('tap', function(event) {
				userPicker.show(function(items) {
					sex.innerHTML =items[0].text;
					doc.querySelector("input[name=sex]").value = items[0].index
				});
			}, false);
		});
	})(mui, document);

</script>